package com.ext.aic.apis.user;

import android.content.Context;

import androidx.lifecycle.LifecycleOwner;

import com.ext.aic.apis.ApiDefine;
import com.ext.aic.apis.ApiPaths;
import com.ext.aic.apis.RequestResponse;
import com.ext.aic.beans.response.AuditStatusResponse;
import com.ext.aic.builder.ParamsBuilder;
import com.hjq.http.EasyHttp;
import com.hjq.http.config.IRequestApi;

public class AuditStatusRequest {

    protected void onAuditStatusSuccess(AuditStatusResponse response) {

    }

    protected void onAuditStatusFail() {

    }

    protected void onAuditStatusEnd() {

    }

    public void request(Context context, LifecycleOwner lifecycleOwner, String deviceId) {

        ParamsBuilder builder = new ParamsBuilder();
        builder.add("deviceSerialNumber", deviceId);
        ApiDefine apiDefine = new ApiDefine(ApiPaths.auditStatus, builder);

        EasyHttp.get(lifecycleOwner)
                .api(apiDefine)
                .request(new RequestResponse<AuditStatusResponse>(context, false) {
                    @Override
                    protected void onSuccess(AuditStatusResponse response) {
                        if (response == null) {
                            return;
                        }
                        onAuditStatusSuccess(response);
                    }

                    @Override
                    public void onHttpFail(Throwable throwable) {
                        super.onHttpFail(throwable);
                        onAuditStatusFail();
                    }

                    @Override
                    public void onHttpEnd(IRequestApi api) {
                        super.onHttpEnd(api);
                        onAuditStatusEnd();
                    }
                });
    }
}
